<!DOCTYPE html>
<html lang="zh-Hans-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>data选项:定义初始数据</title>
    <script src="../vue.js"></script>
</head>
<body>
<h2>【例4】computed选项:计算属性</h2>
<hr>
<div id="app">
    <p>总价格：{{总价格}}</p>
    <p>单价：{{price}}</p>
    <p>数量：{{num}}</p>
    <div>
        <button @click="num === 0 ? 0 : num--">减少数量</button>
        <button @click="num++">增加数量</button>
    </div>
</div>
<script>
    let vm = new Vue({
        el: '#app',
        data: {
            price: 20,
            num: 0
        },
        computed: {
            总价格() {
                return this.price * this.num
            }
        }
    })
</script>
<hr>
<p><a href="index.html">返回章节目录</a>
    <script>document.write(document.lastModified); </script>
</p>
</body>
</html>
